<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./JS/vue.js"></script>
</head>

<body>
    <div id="app">
        <cpn @cpn-click="mainclick" :cmovies="movies" :cmessage="message"></cpn>
    </div>
    <template id="cpn">
        <div>
            <h2>{{cmessage}}</h2>
            <button v-for="item in cmovies" :key="item" @click="itemclick(item)">{{item}}
            </button>
        </div>
    </template>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                message: '电影',
                movies: ['存储', '重启', '让出']
            },
            methods: {
                mainclick(item) {
                    console.log('mainclick',item)
                }
            },
            components: {
                //子组件
                'cpn': {
                    template: '#cpn',
                    // props: ['cmovies','cmessage'],
                    props: {
                        cmovies: Array,
                        //可以提供默认值
                        cmessage: {
                            type: String,
                            default: '没有传递',
                            required: false
                        }
                    },
                    data() {
                        return {

                        }
                    },
                    methods: {
                        itemclick(item) {
                            this.$emit('cpn-click', item);
                        }
                    }
                }
            }
        })
    </script>
</body>

</html>